package com.edu.internship.glabal.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * code is far away from bug with the animal protecting
 *
 * @author lishiquan
 * @description
 * @date Create in 2018/3/16 10:52
 */
public class Constants {

    private Constants() {
    }

    /**
     * 基本的Constants
     */
    @AllArgsConstructor
    @Getter
    public enum BaseCons {
        // 基础枚举类
        SERIAL_VERSION_UID("serialVersionUID", "序列号名称"),
        EXCEL_2007_SUFFIX("xlsx", "Excel2007后缀"),
        DOT(".", "英文句号"),
        BUFFER_SIZE("8196", "缓冲大小"),
        ;

        private final String code;
        private final String desc;
    }

    /**
     * 是和否的枚举
     */
    @AllArgsConstructor
    @Getter
    public enum YesOrNoEnum {
        // 树的构造
        YES("1", "是"),
        NO("0", "否"),
        YES_EN("y", "是"),
        NO_EN("n", "否"),
        ;

        private final String code;
        private final String desc;
    }

    /**
     * 树形常量
     */
    @AllArgsConstructor
    @Getter
    public enum TreeCons {
        // 树的构造
        ROOT("0", "根节点"),
        IS_LEAF("1", "叶子节点"),
        IS_NOT_LEAF("2", "非叶子节点");

        private final String code;
        private final String desc;
    }

    /**
     * redis用的常量
     */
    @AllArgsConstructor
    @Getter
    public enum RedisKeyCons {
        // redis中的key
        DICTIONARY("dictionary:", "字典"),
        USER_PERMISSIONS("user_permissions:", "用户权限"),
        CAPTCHA("captcha:", "验证码"),
        ;

        private final String code;
        private final String desc;
    }

    @Getter
    @AllArgsConstructor
    public enum CaptchaTypeCons {
        // 常量
        WORD_CAPTCHA("1", "字符类型验证码"),
        ARITHMETIC_CAPTCHA("2", "算术类型验证码"),
        ;

        private final String code;
        private final String desc;
    }

    @Getter
    @AllArgsConstructor
    public enum CalcTypeCons {
        // 常量
        PLUS(0, "+"),
        MINUS(1, "-"),
        MULTI(2, "*"),
        DIV(3, "/"),
        ;

        private final Integer code;
        private final String desc;

        public static CalcTypeCons codeOf(Integer code) {
            return Stream.of(values()).filter(e -> Objects.equals(e.getCode(), code)).findAny().orElse(PLUS);
        }
    }

}
